<template>
  <div class="booksItem">
    <div class="heads">
      <div class="fh" @click="$router.go(-1)">
        <span class="iconfont icon-arrow-left-bold"></span> 返回
      </div>
      <div class="center">目录<span>共(1999)章</span></div>
      <router-link class="shuJ" tag="div" to="/bookshelf"><span class="iconfont icon-shujia"></span> 书架</router-link>
    </div>
    <div class="top">
      <div class="list">
        <select name="" id="" @change="getValue" ref="index">
          <option :value="item" v-for="item in nub" :key="item">{{order=="正序"? (item-1)*20+1:(nub-item)*20+1}}-{{order=="正序"? (item-1)*20+21:(nub-item)*20+1-20}}章</option>
        </select>
      </div>
      <button class="btn" @click="setOrder">{{order}}</button>
    </div>
    <div class="listData">
       <ul>
        <li v-for="item in list" :key="item.title" @click="goChapter(item.secId)">
          <div class="left">{{ item.title }}</div>
          <div class="iconfont icon-suo" v-if="item.needPay"></div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
        listData:null,
        list:null,
        nub:null,
        order: "正序",
        BookId:null
    };
  },
  methods: {
    setOrder() {
      this.order = this.order == "正序" ? "倒序" : "正序";
    },
    getValue(e){
        let index=e.target.value;
        this.list=this.listData.slice((index-1)*20,(index-1)*20+21)//0,21  20,41  40,60
    },
    goChapter(zId){
        this.$router.push({path:'/chapter'});
        this.$store.commit('zId', zId)
    }
  },
  filters: {},
  watch: {
    titles() {
      let str = this.titles;
      this.titles = str.split(" ");
      console.log(this.titles);
    },
    order(){
        this.listData.reverse()
        console.log(this.listData);
        console.log(this.$refs.index.value)
       this.list=this.listData.slice((this.$refs.index.value-1)*20,this.$refs.index.value*20+21)//0,21  20,41  40,60
    }
  },
  created() {
    console.log(this.l);
    this.BookId=this.$store.state.id
    this.listData=this.$store.state.booksList;
    //0,21   20,41  40,61
    this.nub=Math.floor(this.listData.length/20);
    this.list=this.listData.slice(0,21)
  },

};
</script>

<style lang="less">
.booksItem {
  // overflow: hidden;
  .heads {
    display: flex;
    justify-content: space-between;
    color: #fff;
    background-color: black;
    height: 50px;
    line-height: 50px;
    .center {
      font-size: 20px;
      span {
        font-size: 14px;
      }
    }
  }
  .top {
    display: flex;
    padding: 12px 8px;
    justify-content: space-between;
    .list {
      width: 80%;
      height: 30px;
      select {
        width: 100%;
        height: 100%;
        background-color: rgb(255, 242, 216);
        border: 1px solid rgb(241, 218, 171);
        border-radius: 6px;
        &:focus-visible{
          outline:none;
        }
      }
    }
    .btn {
      width: 70px;
      height: 30px;
      line-height: 30px;
      border: 1px solid #cecece;
      border-radius: 3px;
      margin-left: 5px;
    }
  }
  .listData{
      ul {
      background-color: #fafafa;

      li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 13px;
        padding: 0 7px;
        height: 40px;
        line-height: 40px;
        height: 40px;
        border-bottom: 1px solid #dfdfdf;
        &:nth-child(1) {
          border-top: 1px solid #dfdfdf;
        }
        .left{
            white-space: nowrap;
          text-overflow: ellipsis;
          width: 320px;
          overflow: hidden;
        }
        .right {
          color: #4c4c4c;
          background: #f2f2f2;
          font-size: 13px;
          border: 1px solid #dfdfdf;
          border-radius: 3px;
          width: 65px;
          height: 30px;
          line-height: 30px;
          text-align: center;
        }
      }
    }
  }
}
</style>